package com.lyt.dao;

import com.lyt.bean.PaperQuestion;
import com.lyt.bean.Question;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
/**
 * @Author: zjx
 * @Date: 2023/04/27/20:03
 * @Description:
 */
@Repository
public interface QuestionDao {

    @Select("select * from paper_question where paper_id =#{id}")
    public List<PaperQuestion> getPaperQuestionById(int id);

    @Select("select * from question where question_id =#{id}")
    public Question getQuestionById(int id);

    @Select("select question_id,question_name,type from question ")
    public List<Question> getQuestionList();

    @Select("select * from question ")
    public List<Question> getAllQuestion();

    @Update("update question set question_name=#{questionName},content=#{content},score=#{score}," +
            "answer=#{answer},detail=#{detail} where question_id = #{questionId}")
    public int updateQuestion(Question question);//根据试卷编号更新试题

    @Delete("delete from question where question_id = #{questionId}")
    public int deleteQuestion(Integer questionId);//根据试题编号删除试题

    @Insert("insert into question values(#{questionId},#{questionName},#{type},#{content}," +
            "#{score},#{userId},#{time},#{answer},#{detail},#{courseId})")
    public int addQuestion(Question question);//创建试题

    @Select("select * from question where question_id = #{questionId}")
    public Question getquestionByquestionId(int questionId);//根据试题id获取所有试题

    @Select("select * from question where course_id = #{courseId}")
    public List<Question> getAllByCourseQuestion(int courseId);//根据课程id获取所有试题

    @Select("select * from question where user_id = #{userId}")
    public List<Question> getAllByUserIdQuestion(int userId);//根据创建者id获取所有试题

    @Select("select * from question where type = #{type}")
    public List<Question> getAllBytypeuestion(int type);//根据创建者id获取所有试题 zjx

    @Select("select * from paper_question pq,question q where pq.question_id = q.question_id and pq.paper_id = #{paperId}")
    public List<Question> selectUnion(int paperId);//获取所有试卷中的试题

    //二级查询
    public List<Question> getAllQuestionByCourseIdOrType(Integer type,Integer courseId);
}
